package com.avic.map.service.impl;

import com.avic.map.common.util.ex.BizErrorCode;
import com.avic.map.common.util.ex.BizException;
import com.avic.map.dal.condition.PageQueryMapAudioCondition;
import com.avic.map.dal.model.MapAudio;
import com.avic.map.service.MapAudioService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author huangsheng on 2018/12/23
 */
@Service
@Slf4j
public class MapAudioServiceImpl extends AbstractServiceImpl implements MapAudioService {

    @Override
    public List<MapAudio> queryAudioListRecords(PageQueryMapAudioCondition pageQueryMapAudioCondition) {
        return mapAudioMapper.queryAudioListRecords(pageQueryMapAudioCondition);
    }

    @Override
    public int queryAudioListRecordsTotalCount(PageQueryMapAudioCondition pageQueryMapAudioCondition) {
        return mapAudioMapper.queryAudioListRecordsTotalCount(pageQueryMapAudioCondition);
    }

    @Override
    public int insert(MapAudio mapAudio) {
        try {
            mapAudioMapper.insert(mapAudio);

            return mapAudio.getId();
        } catch (Exception e) {
            log.error("新增语音通话记录时发生错误:{}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }

    @Override
    public void delete(int audioId) {
        try {
            mapAudioMapper.delete(audioId);
        } catch (Exception e) {
            log.error("删除语音通话记录时发生错误：{}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }
}
